//---SShader---------------------------------------------------------
#include "CShaderObject.h"

//---Using-----------------------------------------------------------
using namespace SShader;

//-------------------------------------------------------------------

CShaderObject::CShaderObject(string _sVertex, string _sPixel) :
GlslShader(_sVertex, _sPixel),
m_uiElementBuffer(0),
m_uiTailleElementBuffer(0)
{
   m_iMiseajour = STATIC_DRAW ;
   m_isVAO = false ;
   m_isCharged = false ;

}

CShaderObject::CShaderObject(const CShader &_shader) :
GlslShader(_shader),
m_uiElementBuffer(0),
m_uiTailleElementBuffer(0)
{
   m_iMiseajour = STATIC_DRAW ;
   m_isVAO = false ;
   m_isCharged = false ;

}

CShaderObject::CShaderObject(const CShaderObject &_copie):
GlslShader(_copie)
{
  m_iMiseajour = _copie.m_iMiseajour ;
  m_isVAO = _copie.m_isVAO ;
  m_isCharged = _copie.m_isCharged  ;
  m_uiElementBuffer = _copie.m_uiElementBuffer ;
  m_uiTailleElementBuffer = _copie.m_uiTailleElementBuffer ;
}

CShaderObject::~CShaderObject() {
  //---Vertex--------------------------
  map<string, void*>::iterator it_map0 ;
  for (it_map0 = m_vData.begin() ; it_map0 !=  m_vData.end() ; ++it_map0) {
    switch (m_vType [it_map0->first] [0]) {
          case FLOAT:
          {
              vector<float>* vec = ((vector<float>*)(it_map0->second)) ;
              delete vec ;
          }
          break;
          case BOOL:
          {
            vector<bool>* vec = ((vector<bool>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case UINT:
          {
            vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case INT:
          {
            vector<int>* vec = ((vector<int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
      }
    }

  map<string, int* >::iterator it_map1 ;
  for (it_map1 = m_vType.begin() ; it_map1 !=  m_vType.end() ; ++it_map1) {
    delete[] (it_map1->second) ;
  }

  //---Normal--------------------------
  for (it_map0 = m_vDataNormal.begin() ; it_map0 !=  m_vDataNormal.end() ; ++it_map0) {
    switch (m_vTypeNormal [it_map0->first] [0]) {
          case FLOAT:
          {
              vector<float>* vec = ((vector<float>*)(it_map0->second)) ;
              delete vec ;
          }
          break;
          case BOOL:
          {
            vector<bool>* vec = ((vector<bool>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case UINT:
          {
            vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case INT:
          {
            vector<int>* vec = ((vector<int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
      }
    }

  for (it_map1 = m_vTypeNormal.begin() ; it_map1 !=  m_vTypeNormal.end() ; ++it_map1) {
    delete[] (it_map1->second) ;
  }

  //---Color---------------------------
  for (it_map0 = m_vDataColor.begin() ; it_map0 !=  m_vDataColor.end() ; ++it_map0) {
    switch (m_vTypeColor [it_map0->first] [0]) {
          case FLOAT:
          {
              vector<float>* vec = ((vector<float>*)(it_map0->second)) ;
              delete vec ;
          }
          break;
          case BOOL:
          {
            vector<bool>* vec = ((vector<bool>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case UINT:
          {
            vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
          case INT:
          {
            vector<int>* vec = ((vector<int>*)(it_map0->second)) ;
            delete vec ;
          }
          break;
      }
    }

  for (it_map1 = m_vTypeColor.begin() ; it_map1 !=  m_vTypeColor.end() ; ++it_map1) {
    delete[] (it_map1->second) ;
  }
 
}

void CShaderObject::setModeUpdate (int _iMiseajour) {
  m_iMiseajour = _iMiseajour ;
}

void CShaderObject::setActiveVAO (bool _isActive) {
  m_isVAO = _isActive ;
}

void CShaderObject::initObject () {
  if (m_isCharged) {
    return ;
  }

  initShader() ;

  string name ;
  int iDimension ;
  int iDebut = 0 ;
  GLsizei stride ;
  //--Vertex------------------------------------------------------------
  map<string, void*>::iterator it_map ;
  for (it_map = m_vData.begin() ; it_map !=  m_vData.end() ; ++it_map) {

   name = it_map->first ;
   iDimension = m_vType [name] [1]  ;

    switch (m_vType [name] [0]) {
      case FLOAT:
      {
          vector<float>* vec = ((vector<float>*)(it_map->second)) ;
          stride = sizeof (float) * iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, FLOAT, vec->size(),  &(*vec)[0]) ;
      }
      break;
      case UINT:
      {
          vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map->second)) ;
          stride = sizeof (unsigned int) *  iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, UINT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case INT:
      {
        vector<int>* vec = ((vector<int>*)(it_map->second)) ;
        stride = sizeof (int) *  iDimension ;
        GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, INT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case BOOL:
      {
        vector<bool>* vec = ((vector<bool>*)(it_map->second)) ;
         stride = sizeof (bool) *  iDimension ;
          bool *tmp = new bool [vec->size()] ;
          for (unsigned int i=0 ; i<vec->size() ; ++i) {
            tmp[i] = (*vec)[i] ;
          }
         GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, BOOL,  vec->size(),  tmp) ;
          delete[] tmp ;
      }
      break;
    }

  if (m_isVAO) {
    InitialiseVAO () ;
  }
    m_isCharged = true ;
  }

  //---Normal-----------------------------------------------------------
  for (it_map = m_vDataNormal.begin() ; it_map !=  m_vDataNormal.end() ; ++it_map) {

    name = it_map->first ;
    iDimension = m_vTypeNormal [name] [1]  ;

    switch (m_vTypeNormal [name] [0]) {
      case FLOAT:
      {
          vector<float>* vec = ((vector<float>*)(it_map->second)) ;
          stride = sizeof (float) * iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, FLOAT, vec->size(),  &(*vec)[0]) ;
      }
      break;
      case UINT:
      {
          vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map->second)) ;
          stride = sizeof (unsigned int) *  iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, UINT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case INT:
      {
        vector<int>* vec = ((vector<int>*)(it_map->second)) ;
        stride = sizeof (int) *  iDimension ;
        GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, INT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case BOOL:
      {
        vector<bool>* vec = ((vector<bool>*)(it_map->second)) ;
         stride = sizeof (bool) *  iDimension ;
          bool *tmp = new bool [vec->size()] ;
          for (unsigned int i=0 ; i<vec->size() ; ++i) {
            tmp[i] = (*vec)[i] ;
          }
         GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, BOOL,  vec->size(),  tmp) ;
          delete[] tmp ;
      }
      break;
    }

  if (m_isVAO) {
    InitialiseVAO () ;
  }
    m_isCharged = true ;
  }

  //---Color-----------------------------------------------------------
  for (it_map = m_vDataColor.begin() ; it_map !=  m_vDataColor.end() ; ++it_map) {

    name = it_map->first ;
    iDimension = m_vTypeColor [name] [1]  ;

    switch (m_vTypeColor [name] [0]) {
      case FLOAT:
      {
          vector<float>* vec = ((vector<float>*)(it_map->second)) ;
          stride = sizeof (float) * iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, FLOAT, vec->size(),  &(*vec)[0]) ;
      }
      break;
      case UINT:
      {
          vector<unsigned int>* vec = ((vector<unsigned int>*)(it_map->second)) ;
          stride = sizeof (unsigned int) *  iDimension ;
          GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, UINT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case INT:
      {
        vector<int>* vec = ((vector<int>*)(it_map->second)) ;
        stride = sizeof (int) *  iDimension ;
        GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, INT, vec->size(),  &(*vec)[0] ) ;
      }
      break;
      case BOOL:
      {
        vector<bool>* vec = ((vector<bool>*)(it_map->second)) ;
         stride = sizeof (bool) *  iDimension ;
          bool *tmp = new bool [vec->size()] ;
          for (unsigned int i=0 ; i<vec->size() ; ++i) {
            tmp[i] = (*vec)[i] ;
          }
         GlslShader::addDonneVertex(&name, &stride, &iDebut, &iDimension , 1, m_iMiseajour, GL_ARRAY_BUFFER, BOOL,  vec->size(),  tmp) ;
          delete[] tmp ;
      }
      break;
    }

  if (m_isVAO) {
    InitialiseVAO () ;
  }
    m_isCharged = true ;
  }

  glGenBuffers (1, &m_uiElementBuffer);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiElementBuffer) ;
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*m_uiTailleElementBuffer, &(m_vElementBuffer[0]), m_iMiseajour);
}

void CShaderObject::Draw(int _iAffichage) {
  enableShader() ;
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiElementBuffer);
    glDrawElements(_iAffichage , m_uiTailleElementBuffer, GL_UNSIGNED_INT,0);
  disableShader() ;
}

//---Element Buffer----------------------------------------------------------------------------
void CShaderObject::addIndex(unsigned int _uiValue) {
  m_vElementBuffer.push_back(_uiValue) ;
  m_uiTailleElementBuffer = m_vElementBuffer.size() ;
}

void CShaderObject::setIndex(unsigned int _uiIndex, unsigned int _uiValue) {
  m_vElementBuffer[_uiIndex] = _uiValue ;
}

//---Vertex------------------------------------------------------------------------------------
bool CShaderObject::addDonneVertex (string _sName, unsigned int  _data1, unsigned int  _data2,  unsigned int _data3, unsigned int _data4) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
       int *tmp = new  int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 4 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<unsigned int> ;
      it  = m_vData.find(_sName);
    }

    if (m_vType[_sName] [0] == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      vec ->push_back((unsigned int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, unsigned int  _data1, unsigned int  _data2, unsigned int _data3) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 3 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<unsigned int> ;
      it  = m_vData.find(_sName);
    }

    if (m_vType[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      return true;
    }
    return false ;

}

bool CShaderObject::addDonneVertex (string _sName, unsigned int  _data1, unsigned int  _data2) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 2 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<unsigned int> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, int _data1, int _data2, int _data3, int _data4) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 4 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<int> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      vec ->push_back((int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, int _data1, int _data2, int _data3) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 3 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<int> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, int _data1, int _data2) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 2 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<int> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, float _data1, float _data2, float _data3, float _data4) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 4 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<float> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0] == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      vec ->push_back((float)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, float _data1, float _data2, float _data3) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 3 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<float> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, float _data1, float _data2) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 2 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<float> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, bool _data1, bool _data2, bool _data3, bool _data4) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 4 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<bool> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      vec ->push_back((bool)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, bool _data1, bool _data2, bool _data3) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 3 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<bool> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneVertex (string _sName, bool _data1, bool _data2) {
    map<string, void*>::iterator it  = m_vData.find(_sName);
    if ( it == m_vData.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 2 ;
      m_vType[_sName] = tmp ;
      m_vData[_sName] = new vector<bool> ;
      it  = m_vData.find(_sName);
    } 

    if (m_vType[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      return true;
    }
    return false ;
}

//---Normal------------------------------------------------------------------------------------
bool CShaderObject::addDonneNormal (string _sName, unsigned int  _data1, unsigned int  _data2,  unsigned int _data3, unsigned int _data4) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
       int *tmp = new  int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 4 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<unsigned int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0] == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      vec ->push_back((unsigned int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, unsigned int  _data1, unsigned int  _data2, unsigned int _data3) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 3 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<unsigned int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      return true;
    }
    return false ;

}

bool CShaderObject::addDonneNormal (string _sName, unsigned int  _data1, unsigned int  _data2) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 2 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<unsigned int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, int _data1, int _data2, int _data3, int _data4) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 4 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      vec ->push_back((int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, int _data1, int _data2, int _data3) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 3 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, int _data1, int _data2) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 2 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<int> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, float _data1, float _data2, float _data3, float _data4) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 4 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<float> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0] == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      vec ->push_back((float)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, float _data1, float _data2, float _data3) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 3 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<float> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, float _data1, float _data2) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 2 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<float> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, bool _data1, bool _data2, bool _data3, bool _data4) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 4 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<bool> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      vec ->push_back((bool)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, bool _data1, bool _data2, bool _data3) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 3 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<bool> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneNormal (string _sName, bool _data1, bool _data2) {
    map<string, void*>::iterator it  = m_vDataNormal.find(_sName);
    if ( it == m_vDataNormal.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 2 ;
      m_vTypeNormal[_sName] = tmp ;
      m_vDataNormal[_sName] = new vector<bool> ;
      it  = m_vDataNormal.find(_sName);
    }

    if (m_vTypeNormal[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      return true;
    }
    return false ;
}

//---Color------------------------------------------------------------------------------------
bool CShaderObject::addDonneColor (string _sName, unsigned int  _data1, unsigned int  _data2,  unsigned int _data3, unsigned int _data4) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
       int *tmp = new  int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 4 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<unsigned int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0] == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      vec ->push_back((unsigned int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, unsigned int  _data1, unsigned int  _data2, unsigned int _data3) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 3 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<unsigned int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      vec->push_back((unsigned int)(_data3))  ;
      return true;
    }
    return false ;

}

bool CShaderObject::addDonneColor (string _sName, unsigned int  _data1, unsigned int  _data2) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = UINT ;
      tmp[1] = 2 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<unsigned int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == UINT) {
      vector<unsigned int>* vec = ((vector<unsigned int>*)(it->second)) ;
      vec->push_back((unsigned int)(_data1))  ;
      vec ->push_back((unsigned int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, int _data1, int _data2, int _data3, int _data4) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 4 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      vec ->push_back((int)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, int _data1, int _data2, int _data3) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 3 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      vec->push_back((int)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, int _data1, int _data2) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = INT ;
      tmp[1] = 2 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<int> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0] == INT) {
      vector<int>* vec = ((vector<int>*)(it->second)) ;
      vec->push_back((int)(_data1))  ;
      vec ->push_back((int)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, float _data1, float _data2, float _data3, float _data4) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 4 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<float> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0] == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      vec ->push_back((float)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, float _data1, float _data2, float _data3) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 3 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<float> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      vec->push_back((float)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, float _data1, float _data2) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = FLOAT ;
      tmp[1] = 2 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<float> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == FLOAT) {
      vector<float>* vec = ((vector<float>*)(it->second)) ;
      vec->push_back((float)(_data1))  ;
      vec ->push_back((float)(_data2))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, bool _data1, bool _data2, bool _data3, bool _data4) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 4 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<bool> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      vec ->push_back((bool)(_data4))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, bool _data1, bool _data2, bool _data3) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 3 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<bool> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      vec->push_back((bool)(_data3))  ;
      return true;
    }
    return false ;
}

bool CShaderObject::addDonneColor (string _sName, bool _data1, bool _data2) {
    map<string, void*>::iterator it  = m_vDataColor.find(_sName);
    if ( it == m_vDataColor.end() ) {
      int *tmp = new int [2] ;
      tmp[0] = BOOL ;
      tmp[1] = 2 ;
      m_vTypeColor[_sName] = tmp ;
      m_vDataColor[_sName] = new vector<bool> ;
      it  = m_vDataColor.find(_sName);
    }

    if (m_vTypeColor[_sName] [0]  == BOOL) {
      vector<bool>* vec = ((vector<bool>*)(it->second)) ;
      vec->push_back((bool)(_data1))  ;
      vec ->push_back((bool)(_data2))  ;
      return true;
    }
    return false ;
}
